﻿namespace EFMLEditor.Internal.Dialogs
{
    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.Windows.Forms;

    using EFMLEditor.Internal.Controls.Components;

    public partial class NewProjectDialog : Form
    {
        public NewProjectDialog()
        {
            this.InitializeComponent();

            var p = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\EFML-Studio\Projects\";
            textBox3.Text = p;
        }

        private void wizardControl1_FinishButtonClick(object sender, EventArgs e)
        {
            ProjectBuilder.Build(textBox3.Text, textBox1.Text, textBox2.Text, textBox8.Text, textBox6.Text, textBox5.Text, textBox7.Text, textBox4.Text);
            Project.Add("project_path", textBox3.Text);
            Project.Add("application_name", textBox1.Text);
            Project.Add("application_icon", textBox2.Text);
            Project.Add("application_author", textBox8.Text);
            Project.Add("application_version", textBox6.Text);
            Project.Add("application_copyright", textBox5.Text);
            Project.Add("application_description", textBox7.Text);
            Project.Add("application_website", textBox4.Text);

            var treeNode = TreeProjectBuilder.Build(textBox1.Text, new Dictionary<string, string> {{"main.window", "main.code"}}, new List<string> {CultureInfo.CurrentCulture.Name+".string"});
            Global.Add("projectNode", treeNode);

            this.Close();
        }

        private void NewProjectDialog_Load(object sender, EventArgs e)
        {
            this.comboBox1.SelectedIndex = 0;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            var openFileDialog1 = EditorFileDialog.NewOpen();
            if(openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox2.Text = openFileDialog1.FileName;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if(folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox3.Text = folderBrowserDialog1.SelectedPath;
            }
        }
    }
}